package in.muton.edushare.components.calendar.api;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

public class CalendarPanelHelper {
	public static int getNumberofBlankDays(Date date){
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(date);
		gc.set(Calendar.DAY_OF_MONTH, 1);
		int firstDayofMonth = gc.get(Calendar.DAY_OF_WEEK);
		switch(firstDayofMonth){
		case Calendar.MONDAY:
			return 0;
		case Calendar.TUESDAY:
			return 1;
		case Calendar.WEDNESDAY:
			return 2;
		case Calendar.THURSDAY:
			return 3;
		case Calendar.FRIDAY:
			return 4;
		case Calendar.SATURDAY:
			return 5;
		case Calendar.SUNDAY:
			return 6;
		default:
			return 0;
		}
	}
	
	public static List<Date> getListOfDays(Date date){
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(date);
		gc.set(Calendar.DAY_OF_MONTH, 1);
		int days = gc.getActualMaximum(Calendar.DAY_OF_MONTH);
		int blanks = CalendarPanelHelper.getNumberofBlankDays(date);
		gc.add(Calendar.DATE,-blanks);
		List<Date> dayList = new ArrayList<Date>();
		for(int i=0;i<days+blanks;i++){
			dayList.add(gc.getTime());
			gc.add(Calendar.DATE, 1);
		}	
		return dayList;
	}
}
